package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsService;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsServiceDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2021-07-05 11:06:18
 */
public class LbsServiceConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsServiceConverts.class);

    public static List<LbsServiceDTO> convert(List<LbsService> lbsServiceList) {
        if (CollectionUtils.isEmpty(lbsServiceList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsServiceDTO> lbsServiceListResult = Lists.newArrayList();
        for (LbsService lbsService : lbsServiceList) {
            lbsServiceListResult.add(convert(lbsService));
        }
        return lbsServiceListResult;
    }

    public static LbsServiceDTO convert(LbsService lbsService) {
        try {
            return BeanUtils.copy(lbsService, LbsServiceDTO.class);
        } catch (Exception e) {
            LOG.error("LbsService到LbsServiceDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsService到LbsServiceDTO转换失败", e);
        }
    }

    public static LbsService convert(LbsServiceDTO lbsServiceDTO) {
        try {
            return BeanUtils.copy(lbsServiceDTO, LbsService.class);
        } catch (Exception e) {
            LOG.error("LbsServiceDTO到LbsService转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsServiceDTO到LbsService转换失败", e);
        }
    }
}